package edu.zut.cs.network.exercise.practice.polymorphic.name;

import java.lang.Comparable;

public class Person extends Name implements Comparable {

	public Person(String firstname, char mi, String lastname, String name) {
		super(firstname, mi, lastname);
		this.name = name;
	}

	public String name;

	public String getName() {
		return name;
	}

	public String toString() {
		return firstname + " " + mi + " " + lastname + "\n";
	}

	public boolean equals(Object obj) {
		if (getClass() != obj.getClass())
			return false;
		Person other = (Person) obj;
		if (name == null && other.getName() != null)
			return false;
		else if (!this.name.equals(other.getName()))
			return false;
		if (firstname != other.getFirstname())
			return false;
		if (mi != other.getMi())
			return false;
		if (lastname != other.getLastname())
			return false;
		return true;
	}

	/**
	 * 排序方式：lastname->firstname->mi
	 */
	public int compareTo(Object obj) {
		Person other = (Person) obj;
		if (lastname.compareTo(other.getLastname()) > 0)
			return 1;
		if (lastname.compareTo(other.getLastname()) < 0)
			return -1;
		if (firstname.compareTo(other.getFirstname()) > 0)
			return 1;
		if (firstname.compareTo(other.getFirstname()) < 0)
			return -1;
		if (mi > other.getMi())
			return 1;
		if (mi < getMi())
			return -1;
		return 0;
	}
}
